/**
 * 
 */
package com.thinkgem.jeesite.modules.childtijianrecord.entity;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFPrintSetup;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import com.thinkgem.jeesite.common.utils.Encodes;
import com.thinkgem.jeesite.modules.sys.utils.DictUtils;

/**
* @author lihuan
* @date 2018年12月30日
* @description 
*	TODO
*
*/
public class ChildRecordExport {
	
	/**
	 * @author lihuan  导出体检统计报表模板
	 */
    public static void Export(List<Map<String,Object>> maps, HttpServletResponse response, String fileName,String name) throws IOException {
    	Map<String,Object> map = null;
    	SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
    	// 创建一个Workbook  
        HSSFWorkbook workbook = new HSSFWorkbook();  
        // 创建一个sheet页  
        HSSFSheet sheet = workbook.createSheet();  
        //样式
        HSSFCellStyle cellStyle = workbook.createCellStyle();  
        HSSFCellStyle style = workbook.createCellStyle(); 
        cellStyle.setAlignment(XSSFCellStyle.ALIGN_CENTER); // 居中  
        cellStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);//垂直
        //设置字体样式
        HSSFFont font=workbook.createFont();
        font.setFontHeightInPoints((short)15);
        font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);         //字体增粗
        font.setFontName("宋体");
        //把字体应用到当前的样式
        style.setFont(font);
        style.setAlignment(XSSFCellStyle.ALIGN_CENTER); // 居中  
        style.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);//垂直
        //设置打印样式
        HSSFPrintSetup print = (HSSFPrintSetup) sheet.getPrintSetup(); 
        print.setLandscape(true);//设置横向打印 
        print.setScale((short) 100);//设置打印缩放100% 
        print.setPaperSize(HSSFPrintSetup.A4_PAPERSIZE);//设置为A4纸张
        sheet.createFreezePane(0, 4, 0, 4);  //冻结表头
        sheet.setPrintGridlines(true);//打印设置网格线
        sheet.setHorizontallyCenter(true); //水平居中
        sheet.setRepeatingRows(new CellRangeAddress(0, 4, 0, 24));//设置打印每页都显示表头
        //设置列宽
        sheet.setColumnWidth(0,1600);
        sheet.setColumnWidth(1,1200);
        sheet.setColumnWidth(2,1200);
        sheet.setColumnWidth(3,1400);
        sheet.setColumnWidth(4,1200);
        sheet.setColumnWidth(5,1200);
        sheet.setColumnWidth(6,1200); 
        sheet.setColumnWidth(7,1200);
        sheet.setColumnWidth(8,1200);
        sheet.setColumnWidth(9,1600);
        sheet.setColumnWidth(10,2200);
        sheet.setColumnWidth(11,2200);
        sheet.setColumnWidth(12,1200);
        sheet.setColumnWidth(13,1200);
        sheet.setColumnWidth(14,800); 
        sheet.setColumnWidth(15,1200);
        sheet.setColumnWidth(16,1200);
        sheet.setColumnWidth(17,1200);
        sheet.setColumnWidth(18,1200);
        sheet.setColumnWidth(19,1600);
        sheet.setColumnWidth(20,1200);
        sheet.setColumnWidth(21,1200);
        sheet.setColumnWidth(22,1200);
        sheet.setColumnWidth(23,1600);
        sheet.setColumnWidth(24,1600);
        sheet.setDefaultRowHeight((short)360);//设置行高
        // 创建第一行  
        HSSFRow row0 = sheet.createRow(0);
        HSSFRow row1 = sheet.createRow(1); 
        HSSFRow row2 = sheet.createRow(2);
        HSSFRow row3 = sheet.createRow(3);
        //设置表头行高
        row0.setHeight((short)500);
        row1.setHeight((short)400);
        row2.setHeight((short)600);
        row3.setHeight((short)700);
        
        CellRangeAddress cra=new CellRangeAddress(0, 0, 0, 24);
        CellRangeAddress cra1=new CellRangeAddress(1, 1, 0, 9);
        CellRangeAddress cra2=new CellRangeAddress(1, 1, 10, 24);
        CellRangeAddress cra3=new CellRangeAddress(2, 3, 0, 0);
        CellRangeAddress cra4=new CellRangeAddress(2, 3, 1, 1);
        CellRangeAddress cra5=new CellRangeAddress(2, 3, 2, 2);
        CellRangeAddress cra6=new CellRangeAddress(2, 3, 3, 3);
        CellRangeAddress cra7=new CellRangeAddress(2, 2, 4, 6);
        CellRangeAddress cra8=new CellRangeAddress(2, 2, 7, 9);
        CellRangeAddress cra9=new CellRangeAddress(2, 3, 10, 10);
        CellRangeAddress cra10=new CellRangeAddress(2, 3, 11, 11);
        CellRangeAddress cra11=new CellRangeAddress(2, 2, 12, 24);
        
        sheet.addMergedRegion(cra);
        sheet.addMergedRegion(cra1);
        sheet.addMergedRegion(cra2);
        sheet.addMergedRegion(cra3);
        sheet.addMergedRegion(cra4);
        sheet.addMergedRegion(cra5);
        sheet.addMergedRegion(cra6);
        sheet.addMergedRegion(cra7);
        sheet.addMergedRegion(cra8);
        sheet.addMergedRegion(cra9);
        sheet.addMergedRegion(cra10);
        sheet.addMergedRegion(cra11);
        row0.createCell(0).setCellValue("候店小学 2018 年学生体检统计报表 ");
        row0.getCell(0).setCellStyle(style);
        // 创建单元格  
        HSSFCell cell1 = row2.createCell(0);  
        HSSFCell cell2 = row2.createCell(1);  
        HSSFCell cell3 = row2.createCell(2);  
        HSSFCell cell4 = row2.createCell(3);
        HSSFCell cell5 = row2.createCell(4);
        HSSFCell cell6 = row2.createCell(7);
        HSSFCell cell7 = row2.createCell(10);
        HSSFCell cell8 = row2.createCell(11);
        HSSFCell cell9 = row2.createCell(12);
        row3.createCell(4).setCellValue("营养不良");
        row3.createCell(5).setCellValue("正常");
        row3.createCell(6).setCellValue("超重");
        row3.createCell(7).setCellValue("优秀");
        row3.createCell(8).setCellValue("及格");
        row3.createCell(9).setCellValue("不及格");
        row3.createCell(12).setCellValue("血压");
        row3.createCell(13).setCellValue("心脏");
        row3.createCell(14).setCellValue("肺");
        row3.createCell(15).setCellValue("肝脾");
        row3.createCell(16).setCellValue("龋齿");
        row3.createCell(17).setCellValue("牙周");
        row3.createCell(18).setCellValue("沙眼");
        row3.createCell(19).setCellValue("头颈部");
        row3.createCell(20).setCellValue("脊柱");
        row3.createCell(21).setCellValue("胸部");
        row3.createCell(22).setCellValue("四肢");
        row3.createCell(23).setCellValue("皮肤病");
        row3.createCell(24).setCellValue("淋巴结");
        // 设置表头  
        cell1.setCellValue("年级"); 
        cell1.getCellStyle().setAlignment(XSSFCellStyle.ALIGN_CENTER);
        cell1.getCellStyle().setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
        cell1.getCellStyle().setWrapText(true);
        cell2.setCellValue("性别");  
        cell3.setCellValue("体检人数");  
        cell4.setCellValue("各项体检正常人数"); 
        cell5.setCellValue("身高标准体重");
        cell6.setCellValue("肺活量体重指数");
        cell7.setCellValue("正常视力5.3~5.0");
        cell8.setCellValue("视力不良5.0以下");
        cell9.setCellValue("疾病分类");
        
        row1.createCell(0).setCellValue("学校名称： 候店小学");
        row1.createCell(10).setCellValue("体检日期： 2018年9月26日");
        HSSFRow row;
        int sum0 = 0;
        int sum1 = 0;
        int sum2 = 0;
        int sum3 = 0;
        int sum4 = 0;
        int sum5 = 0;
        int sum6 = 0;
        int sum7 = 0;
        int sum8 = 0;
        int sum9 = 0;
        int sum10 = 0;
        int sum11 = 0;
        int sum12 = 0;
        int sum13 = 0;
        int sum14 = 0;
        int sum15 = 0;
        int sum16 = 0;
        int sum17 = 0;
        int sum18 = 0;
        int sum19 = 0;
        int sum20 = 0;
        int sum21 = 0;
        int sum22 = 0;
        Map<String,Object> map1;
        int i = 4;
    	for(int j=0;j<maps.size();j++){
    		map = maps.get(j);
            row = sheet.createRow(i);
            row.setHeight((short)400);
            if(j % 2 ==0){
            	row.createCell(0).setCellValue(DictUtils.getDictLabel(map.get("STU_GRADE").toString(), "stu_grade", ""));
            	row.createCell(1).setCellValue(DictUtils.getDictLabel(map.get("GENDER").toString(), "sex", ""));
            	row.createCell(2).setCellValue(map.get("number").toString());
            	sum0 += Integer.parseInt(map.get("number").toString());
            	row.createCell(3).setCellValue(map.get("healthy").toString());
            	sum1 += Integer.parseInt(map.get("healthy").toString());
            	row.createCell(4).setCellValue(map.get("thin").toString());
            	sum2 += Integer.parseInt(map.get("thin").toString());
            	row.createCell(5).setCellValue(map.get("normal").toString());
            	sum3 += Integer.parseInt(map.get("normal").toString());
            	row.createCell(6).setCellValue(map.get("overweight").toString());
            	sum4 += Integer.parseInt(map.get("overweight").toString());
            	row.createCell(7).setCellValue(map.get("excellent").toString());
            	sum5 += Integer.parseInt(map.get("excellent").toString());
            	row.createCell(8).setCellValue(map.get("pass").toString());
            	sum6 += Integer.parseInt(map.get("pass").toString());
            	row.createCell(9).setCellValue(map.get("flunk").toString());
            	sum7 += Integer.parseInt(map.get("flunk").toString());
            	row.createCell(10).setCellValue(map.get("normalVision").toString());
            	sum8 += Integer.parseInt(map.get("normalVision").toString());
            	row.createCell(11).setCellValue(map.get("porVision").toString());
            	sum9 += Integer.parseInt(map.get("porVision").toString());
            	row.createCell(12).setCellValue(map.get("blood").toString());
            	sum10 += Integer.parseInt(map.get("blood").toString());
            	row.createCell(13).setCellValue(map.get("heart").toString());
            	sum11 += Integer.parseInt(map.get("heart").toString());
            	row.createCell(14).setCellValue(map.get("luny").toString());
            	sum12 += Integer.parseInt(map.get("luny").toString());
            	row.createCell(15).setCellValue(map.get("liver").toString());
            	sum13 += Integer.parseInt(map.get("liver").toString());
            	row.createCell(16).setCellValue(map.get("mouth").toString());
            	sum14 += Integer.parseInt(map.get("mouth").toString());
            	row.createCell(17).setCellValue(map.get("tooth").toString());
            	sum15 += Integer.parseInt(map.get("tooth").toString());
            	row.createCell(18).setCellValue(map.get("trachoma").toString());
            	sum16 += Integer.parseInt(map.get("trachoma").toString());
            	row.createCell(19).setCellValue(map.get("headNeck").toString());
            	sum17 += Integer.parseInt(map.get("headNeck").toString());
            	row.createCell(20).setCellValue(map.get("spine").toString());
            	sum18 += Integer.parseInt(map.get("spine").toString());
            	row.createCell(21).setCellValue(map.get("chestXray").toString());
            	sum19 += Integer.parseInt(map.get("chestXray").toString());
            	row.createCell(22).setCellValue(map.get("limb").toString());
            	sum20 += Integer.parseInt(map.get("limb").toString());
            	row.createCell(23).setCellValue(map.get("skin").toString());
            	sum21 += Integer.parseInt(map.get("skin").toString());
            	row.createCell(24).setCellValue(map.get("lymphGland").toString());
            	sum22 += Integer.parseInt(map.get("lymphGland").toString());
            	i++;
            }else{
            	row.createCell(0).setCellValue(DictUtils.getDictLabel(map.get("STU_GRADE").toString(), "stu_grade", ""));
            	row.createCell(1).setCellValue(DictUtils.getDictLabel(map.get("GENDER").toString(), "sex", ""));
            	row.createCell(2).setCellValue(map.get("number").toString());
            	sum0 += Integer.parseInt(map.get("number").toString());
            	row.createCell(3).setCellValue(map.get("healthy").toString());
            	sum1 += Integer.parseInt(map.get("healthy").toString());
            	row.createCell(4).setCellValue(map.get("thin").toString());
            	sum2 += Integer.parseInt(map.get("thin").toString());
            	row.createCell(5).setCellValue(map.get("normal").toString());
            	sum3 += Integer.parseInt(map.get("normal").toString());
            	row.createCell(6).setCellValue(map.get("overweight").toString());
            	sum4 += Integer.parseInt(map.get("overweight").toString());
            	row.createCell(7).setCellValue(map.get("excellent").toString());
            	sum5 += Integer.parseInt(map.get("excellent").toString());
            	row.createCell(8).setCellValue(map.get("pass").toString());
            	sum6 += Integer.parseInt(map.get("pass").toString());
            	row.createCell(9).setCellValue(map.get("flunk").toString());
            	sum7 += Integer.parseInt(map.get("flunk").toString());
            	row.createCell(10).setCellValue(map.get("normalVision").toString());
            	sum8 += Integer.parseInt(map.get("normalVision").toString());
            	row.createCell(11).setCellValue(map.get("porVision").toString());
            	sum9 += Integer.parseInt(map.get("porVision").toString());
            	row.createCell(12).setCellValue(map.get("blood").toString());
            	sum10 += Integer.parseInt(map.get("blood").toString());
            	row.createCell(13).setCellValue(map.get("heart").toString());
            	sum11 += Integer.parseInt(map.get("heart").toString());
            	row.createCell(14).setCellValue(map.get("luny").toString());
            	sum12 += Integer.parseInt(map.get("luny").toString());
            	row.createCell(15).setCellValue(map.get("liver").toString());
            	sum13 += Integer.parseInt(map.get("liver").toString());
            	row.createCell(16).setCellValue(map.get("mouth").toString());
            	sum14 += Integer.parseInt(map.get("mouth").toString());
            	row.createCell(17).setCellValue(map.get("tooth").toString());
            	sum15 += Integer.parseInt(map.get("tooth").toString());
            	row.createCell(18).setCellValue(map.get("trachoma").toString());
            	sum16 += Integer.parseInt(map.get("trachoma").toString());
            	row.createCell(19).setCellValue(map.get("headNeck").toString());
            	sum17 += Integer.parseInt(map.get("headNeck").toString());
            	row.createCell(20).setCellValue(map.get("spine").toString());
            	sum18 += Integer.parseInt(map.get("spine").toString());
            	row.createCell(21).setCellValue(map.get("chestXray").toString());
            	sum19 += Integer.parseInt(map.get("chestXray").toString());
            	row.createCell(22).setCellValue(map.get("limb").toString());
            	sum20 += Integer.parseInt(map.get("limb").toString());
            	row.createCell(23).setCellValue(map.get("skin").toString());
            	sum21 += Integer.parseInt(map.get("skin").toString());
            	row.createCell(24).setCellValue(map.get("lymphGland").toString());
            	sum22 += Integer.parseInt(map.get("lymphGland").toString());
            	i++;
            	map1 = maps.get(j-1);
            	row = sheet.createRow(i);
            	row.setHeight((short)400);
            	CellRangeAddress cra12 = new CellRangeAddress(i-2, i, 0, 0);
                sheet.addMergedRegion(cra12);
            	row.createCell(0).setCellValue(DictUtils.getDictLabel(map.get("STU_GRADE").toString(), "stu_grade", ""));
            	row.createCell(1).setCellValue("计");
            	row.createCell(2).setCellValue(Integer.parseInt(map.get("number").toString())+Integer.parseInt(map1.get("number").toString()));
            	row.createCell(3).setCellValue(Integer.parseInt(map.get("healthy").toString())+Integer.parseInt(map1.get("healthy").toString()));
            	row.createCell(4).setCellValue(Integer.parseInt(map.get("thin").toString())+Integer.parseInt(map1.get("thin").toString()));
            	row.createCell(5).setCellValue(Integer.parseInt(map.get("normal").toString())+Integer.parseInt(map1.get("normal").toString()));
            	row.createCell(6).setCellValue(Integer.parseInt(map.get("overweight").toString())+Integer.parseInt(map1.get("overweight").toString()));
            	row.createCell(7).setCellValue(Integer.parseInt(map.get("excellent").toString())+Integer.parseInt(map1.get("excellent").toString()));
            	row.createCell(8).setCellValue(Integer.parseInt(map.get("pass").toString())+Integer.parseInt(map1.get("pass").toString()));
            	row.createCell(9).setCellValue(Integer.parseInt(map.get("flunk").toString())+Integer.parseInt(map1.get("flunk").toString()));
            	row.createCell(10).setCellValue(Integer.parseInt(map.get("normalVision").toString())+Integer.parseInt(map1.get("normalVision").toString()));
            	row.createCell(11).setCellValue(Integer.parseInt(map.get("porVision").toString())+Integer.parseInt(map1.get("porVision").toString()));
            	row.createCell(12).setCellValue(Integer.parseInt(map.get("blood").toString())+Integer.parseInt(map1.get("blood").toString()));
            	row.createCell(13).setCellValue(Integer.parseInt(map.get("heart").toString())+Integer.parseInt(map1.get("heart").toString()));
            	row.createCell(14).setCellValue(Integer.parseInt(map.get("luny").toString())+Integer.parseInt(map1.get("luny").toString()));
            	row.createCell(15).setCellValue(Integer.parseInt(map.get("liver").toString())+Integer.parseInt(map1.get("liver").toString()));
            	row.createCell(16).setCellValue(Integer.parseInt(map.get("mouth").toString())+Integer.parseInt(map1.get("mouth").toString()));
            	row.createCell(17).setCellValue(Integer.parseInt(map.get("tooth").toString())+Integer.parseInt(map1.get("tooth").toString()));
            	row.createCell(18).setCellValue(Integer.parseInt(map.get("trachoma").toString())+Integer.parseInt(map1.get("trachoma").toString()));
            	row.createCell(19).setCellValue(Integer.parseInt(map.get("headNeck").toString())+Integer.parseInt(map1.get("headNeck").toString()));
            	row.createCell(20).setCellValue(Integer.parseInt(map.get("spine").toString())+Integer.parseInt(map1.get("spine").toString()));
            	row.createCell(21).setCellValue(Integer.parseInt(map.get("chestXray").toString())+Integer.parseInt(map1.get("chestXray").toString()));
            	row.createCell(22).setCellValue(Integer.parseInt(map.get("limb").toString())+Integer.parseInt(map1.get("limb").toString()));
            	row.createCell(23).setCellValue(Integer.parseInt(map.get("skin").toString())+Integer.parseInt(map1.get("skin").toString()));
            	row.createCell(24).setCellValue(Integer.parseInt(map.get("lymphGland").toString())+Integer.parseInt(map1.get("lymphGland").toString()));
            	i++;
            }
    	}
    	row = sheet.createRow(maps.size()+4);
    	row.setHeight((short)500);
    	row.createCell(0).setCellValue("合计");
    	/*CellRangeAddress cra13=new CellRangeAddress(maps.size()+4, maps.size()+4, 1, 4);
        sheet.addMergedRegion(cra13);*/
 		row.createCell(1).setCellValue("男");
		row.createCell(2).setCellValue(sum0);
		row.createCell(3).setCellValue(sum1);
		row.createCell(4).setCellValue(sum2);
		row.createCell(5).setCellValue(sum3);
		row.createCell(6).setCellValue(sum4);
		row.createCell(7).setCellValue(sum5);
		row.createCell(8).setCellValue(sum6);
		row.createCell(9).setCellValue(sum7);
		row.createCell(10).setCellValue(sum8);
		row.createCell(11).setCellValue(sum9);
		row.createCell(12).setCellValue(sum10);
		row.createCell(13).setCellValue(sum11);
		row.createCell(14).setCellValue(sum12);
		row.createCell(15).setCellValue(sum13);
		row.createCell(16).setCellValue(sum14);
		row.createCell(17).setCellValue(sum15);
		row.createCell(18).setCellValue(sum16);
		row.createCell(19).setCellValue(sum17);
		row.createCell(20).setCellValue(sum18);
		row.createCell(21).setCellValue(sum19);
		row.createCell(22).setCellValue(sum20);
		row.createCell(23).setCellValue(sum21);
		row.createCell(24).setCellValue(sum22);
	   /* Row rowm=sheet.createRow(num);
	    rowm.setHeight((short)500);
	    rowm.createCell(0).setCellValue("统计制表:_________");
	    rowm.createCell(2).setCellValue("统计日期:_________");
	    rowm.createCell(5).setCellValue("领导审批:_________");
	    rowm.createCell(9).setCellValue("审批日期:_________");*/
        response.reset();
        response.setContentType("application/octet-stream; charset=utf-8");
        response.setHeader("Content-Disposition", "attachment; filename="+Encodes.urlEncode(fileName));
        workbook.write(response.getOutputStream());
    }
    
}
